<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<% String path=request.getContextPath(); String basePath=request.getScheme()+ "://" + request.getServerName() + ":" + request.getServerPort() + path+ "/"; %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<base href="<%=basePath%>">
<title>激活卡流转</title>
<%@ include file="/WEB-INF/jsp/common/common.jsp"%>
<script src="js/jquery.divbox.js" type="text/javascript"></script>
<script src="js/getCardPermission.js" type="text/javascript"></script>
<style>
.h_30 {
	height: 30px;
}

.table_body_div {
	padding: 10px 15%;
}

.table_date {
	padding: 20px 0 20px 30%;
}

#date {
	margin-left: 10%;
}

.calendars {
	z-index: 10001;
}

.fr {
	float: right;
}

.fl {
	float: left;
}

.w_50 {
	width: 50%;
}
/* 延期按钮默认隐藏 */
#extension, #extensions {
	display: none;
}
/* 清除浮动 */
.clear::after {
	clear:both;
	content:'.';
	display:block;
	width: 0;
	height: 0;
	visibility:hidden;
}/*==for FF/chrome/opera/IE8==*/
</style>
<script type="text/javascript">
	/* 初始化 start */
	$(function() {
		// 延期权限控制 lfd changed 20181009
		// getusercompower(setBtn)// 获取角色 控制按钮
		getPermission(setBtn)// 获取权限 控制按钮
		queryCardInfo(1)
	})
	/* 初始化 end */
	// 延期权限控制 lfd changed 20181009
	/* 配置按钮 start */
	function setBtn(power) {
	// function setBtn(data) {
    	/* if (data.result==='success') {
    		$('#extension').css('display', 'inline-block')
    		$('#extensions').css('display', 'inline-block')
    	}else{
    		$.message("error", data.message);
    	} */
    	if (power[2] == '1') {
    		$('#extension').css('display', 'inline-block')
            $('#extensions').css('display', 'inline-block')
            // 延期权限控制多选框显示隐藏 lfd changed 20181031 start
            $('#extension_td').css('display', 'table-row')
        } else {
            $('#extension_td').css('display', 'none')
        }
    	// 延期权限控制多选框显示隐藏 lfd changed 20181031 end
    }
	/* 配置按钮 end */
	/* 查询卡库存   start */
	function queryCardInfo(displayPage){
 		var name= $("#name").val();
		var cardDefindId = $("#carDefindId").val();
		var status = $("#status").val();
		var startNo=$("#startNo").val();
		var endNo=$("#endNo").val();
		loadCardData({current:displayPage,size:10,cardDefineName: name, cardDefineId: cardDefindId, status: status,startNo:startNo,endNo:endNo}); 
	}
	function loadCardData(param){
		var jsonDate;
		if(null != param && null != param.current){
			jsonDate =param;	
		}else{
			jsonDate={current:1,size:10};
		}
		$.openLoading();
 		$.ajax({
			url : "actirationCardCirculation/queryStock",
			type : 'POST',
			async : true,
			dataType:'json',
			data: param,
			success : function(page) {
				$.closeLoading();
				$.each(page.data,function(index,item){ 
					item.disableDate=timestampToTime(item.disableDate);
					item.creatDate=timestampToTime(item.creatDate);
					item.operateDate=timestampToTime(item.operateDate);
				});
				var radioObj ="<input class='input_fxk' name='checkBoxCard' type='checkbox' value=''>";
				var fieldNames = "cardDefineId@TDH,cardDefineName,cardNo,deptno,status?{0: '库存'; '1': '上交'; '2': '下发'; '3': '已关联出单方案'; '4': '可激活/已缴费'; '5': '已激活'; '6': '作废'; '7': '锁定状态'; '9':'过期'},totPremamt,receiveDepNo,operateDate,creatDate,disableDate";
				
				// 延期权限控制多选框显示隐藏 lfd changed 20181031 start
				var tableContent
				if ($("#extension").css("display") === 'inline-block') {
					$('#check_th').css("display", "table-cell")
					tableContent = creatTable4(fieldNames, page, radioObj);
				} else {
					$('#check_th').css('display', 'none')
					tableContent = creatTable4(fieldNames, page);
				}
				// 延期权限控制多选框显示隐藏 lfd changed 20181031 end
				
				var tableObj = $("#cardpageTable");
				tableObj.find("tbody").remove();
				tableObj.append(tableContent);
				
				var strPage = creatChannelPage(page.current,6,page.maxPage,"75");
				var pageDIV = $("#cardpageDIV");
				pageDIV[0].innerHTML="";
				pageDIV.append(strPage);
				bindradio();//点击单选按钮，该行高亮显示
			}
		}) 
	}
	/* 查询卡库存   end */
	/* 列表延期 start */
	function cardDelay() {
		var delayList = $.map($("input[name='checkBoxCard']:checked").parent().next().next().next(), function (v, i) {
			return $(v).html()
		})
		
		// lfd added 20181112 校验延期日期晚于今天 start
		var newdate = new Date().getTime()
        var delaydate = new Date($('#date').val().replace(/-/g, '/')).getTime()
		if (delaydate < newdate) {
			$.message("error", "请正确选择延期日期！");
			return false
		}
		// lfd added 20181112 校验延期日期晚于今天 end
		
		var date = $('#date').val().replace(/-/g, '')
		var param = {delayList: delayList, date: date}
		$.openLoading();
		$.ajax({
			url : "actirationCardCirculation/cardDelayList",
			type : 'POST',
			async : true,
			dataType:'json',
			data: param,
			traditional :true,  //注意这个参数是必须的
			success : function(data) {
				$.closeLoading();
				if("success"==data.result&&""!=data.message){
					$.message("success", data.message);
					datedivClose()
					queryCardInfo($('.page_a_click').html())//重新查询当前页面
		    	}
				if("fail"==data.result){
		    		$.message("error", "系统错误,请联系管理员");
		    	}
				if("error"==data.result&&""!=data.message){
		    		$.message("error", data.message);
		    	}
			}
		}) 
		
	}
	/* 列表延期 end */
	/* 批量延期 start */
	function cardDelay1() {
		var startNo = $('#mstartNo').val()
		var endNo = $('#mendNo').val()
		
		// lfd added 20181112 校验延期日期晚于今天 start
        var newdate = new Date().getTime()
        var delaydate = new Date($('#date1').val().replace(/-/g, '/')).getTime()
        if (delaydate < newdate) {
            $.message("error", "请正确选择延期日期！");
            return false
        }
        // lfd added 20181112 校验延期日期晚于今天 end
		
		var date = $('#date1').val().replace(/-/g, '')
		if (!startNo) {
			$.message("error", "请填写开始卡号！ ");
			return
		} else if (!endNo) {
			$.message("error", "请填写结束卡号！ ");
			return
		} else if (!date) {
			$.message("error", "请填写延期日期！ ");
			return
		}
		var param = {date: date, startNo: startNo, endNo: endNo}
		$.openLoading();
 		$.ajax({
			url : "actirationCardCirculation/cardDelay",
			type : 'POST',
			async : true,
			dataType:'json',
			data: param,
			success : function(data) {
				$.closeLoading();
				if("success"==data.result&&""!=data.message){
					$.message("success", data.message);
					datedivClose1()
					queryCardInfo($('.page_a_click').html())//重新查询当前页面
		    	}
				if("fail"==data.result){
		    		$.message("error", "系统错误,请联系管理员");
		    	}
				if("error"==data.result&&""!=data.message){
		    		$.message("error", data.message);
		    	}
			}
		}) 
		
	}
	/* 批量延期 end */
	/* 打开弹窗 start */
	function datedivOpen() {
		if ($("input[name='checkBoxCard']:checked").length <= 0) {
			$.message("error", "请至少选择一张卡延期！");
			return
		}
		$('#dateDiv').OpenDiv()
	}
	/* 打开弹窗 end */
	/* 打开批量弹窗 start */
	function datediv1Open() {
		$('#dateDiv1').OpenDiv()
	}
	/* 打开批量弹窗 end */
	/* 关闭弹窗 start */
	function datedivClose() {
		$('#date').val('')
		closeCurrentDIV('dateDiv')
	}
	/* 关闭弹窗 end */
	/* 关闭批量弹窗  start */
	function datedivClose1() {
		$('#mstartNo').val('')
		$('#mendNo').val('')
		$('#date1').val('')
		closeCurrentDIV('dateDiv1')
	}
	/* 关闭批量弹窗  end */
	/* 多选按钮高亮 start */
    function bindradio(){
		$("input[name='checkBoxCard']").click(function(){
			$("input[name='checkBoxCard']").parent().parent().removeClass("table_highlighter");
			$("input[name='checkBoxCard']:checked").parent().parent().addClass("table_highlighter");
	   	});
    }
    /* 多选按钮高亮 end */
	/* 激活卡下发上交 start */
	function issuedCard () {
		self.location.href="<%=path%>/actirationCardCirculation/issued";
	}
	/* 激活卡下发 end */
	/* 激活卡接收查询 start */
	function receiveCard () {
		self.location.href="<%=path%>/actirationCardCirculation/receive";
	}
	/* 激活卡接收查询 end */
	// 统一 关闭  窗口
	function closeCurrentDIV(obj){
		$("#"+obj).CloseDiv();
	}
	/*转换日期*/
	function timestampToTime(data) {
		if(data!=null){
			  var date = new Date(data); 
		        Y = date.getFullYear() + '-';  
		        M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';  
		        D = date.getDate() + ' ';  
		        h = date.getHours() + ':';  
		        m = date.getMinutes() + ':';  
		        s = date.getSeconds();  
		        return Y+M+D;  	//年-月-日
		}else{
			return data;
		}
    }
	</script>
</head>
<body>
	<div class="current">
		<table class="current_table_1">
			<tbody>
				<tr class="f2">
					<td><img src="./images/current_1.jpg"></td>
					<td class="current_table_1_td"><img src="images/current_1.png">&nbsp;您现在的位置：&nbsp;
						<span style="color: #136bab;">激活卡管理 <span
							style="padding: 0 5px; font-weight: bold; line-height: 28px;">&gt;</span>
							激活卡流转
					</span></td>
					<td><img src="./images/current_3.jpg"></td>
				</tr>
			</tbody>
		</table>
	</div>

	<table class="table_02" id="table">
		<tr>
			<td>
				<table class="search_table">
					<tr height="30px">
						<td width="25%" height="30">卡定义名称： <input name="name"
							id="name" type="text" class="input_text" maxlength="30" value="">
						</td>
						<td width="25%" height="30">卡定义号： <input
							name="carDefindId" id="carDefindId" type="text"
							class="input_text" maxlength="30" value="">
						</td>
						<td width="25%" height="30">流转状态： <select
							class="search_select_1" id="status">
								<option value="">--请选择--</option>
								<option value="0">库存</option>
								<option value="1">上交</option>
								<option value="2">下发</option>
								<option value="3">已关联出单方案</option>
								<option value="4">可激活/已缴费</option>
								<option value="5">已激活</option>
								<option value="6">作废</option>
								<option value="7">锁定状态</option>
								<option value="9">过期</option>
						</select>
						</td>
					</tr>
					<tr height="30px">
						<td width="25%" height="30">开始卡号&nbsp;： <input name="startNo"
							id="startNo" type="number" class="input_text" maxlength="30"
							value="">
						</td>
						<td width="25%" height="30">结束卡号： <input name="endNo"
							id="endNo" type="number" class="input_text" maxlength="30"
							value="">
						</td>
					</tr>
					<tr height="30px">
						<td height="30" colspan="4" style="text-align: center;">
						    <input type="button" class="input_button_1" id="searchBtn" value="查询" onClick="queryCardInfo(1)" /> 
					        <input type="button" class="input_button_1" id="issue_Btn" value="流转" onClick="issuedCard()" /> 
					        <input type="button" class="input_button_1" id="receive_Btn" value="接收" onClick="receiveCard()" /> 
					    </td>
					</tr>
				</table>
			</td>
		</tr>
		<tr  id="extension_td">
			<td>
				<table class="search_table">
					<tr height="30px">
						<td width="30%" height="30">
							<input type="button"
								class="input_button_1" id="extension" value="延期"
								onClick="datedivOpen()" /> 
							<input type="button"
								class="input_button_2" id="extensions" value="批量延期"
								onClick="datediv1Open()" />
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<!-- 数据列表 start -->
		<tr>
			<td>
				<table id="cardpageTable" class="content_table_1">
					<thead>
						<tr class="f1">
							<th style="width: 3%;" id="check_th">选择</th>
							<th style="width: 10%;">卡定义名称</th>
							<th style="width: 5%;">卡号</th>
							<th style="width: 14%;">机构名称</th>
							<th style="width: 4%;">状态</th>
							<th style="width: 5%;">保费</th>
							<th style="width: 14%;">目的机构</th>
							<th style="width: 5%;">操作日期</th>
							<th style="width: 5%;">生成日期</th>
							<th style="width: 5%;">失效日期</th>
						</tr>
					</thead>
					<tbody>
					</tbody>
				</table>
				<div id="cardpageDIV" class="page"></div>
			</td>
		</tr>
		<!-- 数据列表 end -->
	</table>
	<!-- 延期弹窗 start -->
	<div id="dateDiv" style="display: none; width: 60%;">
		<div class="table_title_div">
			<table class="table_title" style='width: 100%; height: 20px;'>
				<tr>
					<td width="10%"></td>
					<td width="80%" id="interfaceName"></td>
					<td width="10%" align="right"><img
						src="./images/closedown.gif" alt="关闭" onclick="datedivClose()" /></td>
				</tr>
			</table>
		</div>
		<div class="table_body_div table_date">
			延长至： <input id="date" onkeydown="false"
				onclick="showCalendar('date','y-mm-dd');" readonly="readonly"
				class="input_time" type="text" />
		</div>
		<div align="center">
			<input class="input_button_3" name="" type="button"
				onclick="cardDelay()" value="确定">&nbsp;&nbsp; <input
				class="input_button_3" name="" type="button"
				onclick="datedivClose()" value="取消">
		</div>
	</div>
	<!-- 延期弹窗 end -->
	<!-- 批量延期 start -->
	<div id="dateDiv1" style="display: none; width:  60%;">
		<div class="table_title_div">
			<table class="table_title" style='width: 100%; height: 20px;'>
				<tr>
					<td width="10%"></td>
					<td width="80%" id="interfaceName"></td>
					<td width="10%" align="right"><img
						src="./images/closedown.gif" alt="关闭" onclick="datedivClose1()" /></td>
				</tr>
			</table>
		</div>
		<div class="table_body_div">
			<div class="table_num clear">
				<div class="fl w_50 h_30">
					<span>开始卡号</span> 
					<input name="mstartNo" id="mstartNo" type="text" class="input_text" maxlength="30" value="">
				</div>
				<div class="fr w_50">
					<span>结束卡号</span> 
					<input name="mendNo" id="mendNo" type="text" class="input_text" maxlength="30" value="">
				</div>
			</div>
			<div class="h_30">
				延长至： <input id="date1" onkeydown="false"
					onclick="showCalendar('date1','y-mm-dd');" readonly="readonly"
					class="input_time" type="text" />
			</div>
		</div>
		<div align="center">
			<input class="input_button_3" type="button" onclick="cardDelay1()" value="确定">&nbsp;&nbsp; 
			<input class="input_button_3" type="button" onclick="datedivClose1()" value="取消">
		</div>
	</div>
	<!-- 批量延期 end -->
</body>
</html>